#include "Avalon/WebServices/WebServiceNode.hpp"
#include "Avalon/Base/Algorithm.hpp"

using namespace Avalon;
using namespace Avalon::Serialization;
using namespace Avalon::WebServices;
using namespace boost;
using namespace boost::signals2;
using namespace std;

WebServiceNode::WebServiceNode(HttpServer* server,
    HttpSessionFactory* sessionFactory, DataShuttleFactory* dataShuttleFactory)
    : m_server(server),
      m_sessionHandler(sessionFactory),
      m_dataShuttleFactory(dataShuttleFactory) {
  m_signalHandler.Start();
}

WebServiceNode::~WebServiceNode() {
  Clear(m_sessions);
  Clear(m_signals);
}

HttpSessionHandler& WebServiceNode::GetSessionHandler() {
  return m_sessionHandler;
}

connection WebServiceNode::ConnectInvalidRequestSignal(
    const HttpSessionHandler::HttpRequestSignal::slot_type& slot) {
  boost::lock_guard<boost::mutex> lock(m_mutex);
  return m_invalidRequestSignal.connect(slot);
}
